package com.ytc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ytc.model.Art;
import com.ytc.model.Hero;
import com.ytc.service.ArtService;
import com.ytc.service.HeroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/hero")
public class HeroController {
    @Autowired
    private HeroService heroService;
    @Autowired
    private ArtService artService;
    @RequestMapping("toShowHero")
    private String toShowHero(Model model,@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum){
        PageHelper.startPage(pageNum, 3); //一定把分页写在上面
      List<Hero> list=heroService.queryHeroList();
        PageInfo<Hero> pageInfo = new PageInfo<Hero>(list);
//      model.addAttribute("list",list);
   model.addAttribute("pageInfo",pageInfo);
        return "hero/showHero";
    }
    @RequestMapping("toAddHero")
    public String toAddHero(Model model){
       List<Art> artList=artService.queryArt();
       model.addAttribute("artList",artList);
        return "hero/addHero";
    }

    @RequestMapping("addHero")
    public String addHero(Hero hero){
        heroService.addHero(hero);
        return "redirect:/hero/toShowHero";
    }
    @RequestMapping("toShowArt")
    public String toShowArt(Model model){
        List<Art> artList=artService.queryArt();
        model.addAttribute("artList",artList);
        return "hero/art/shoArt";
    }
}
